from qiniu import Auth, put_data

access_key = '-K8yO8ChJRicvqmraADA8g9EwjDfw0fjQKnYTWSQ'
secret_key = 'IluJ_nAEm-JVBIISYn3nQRTTt39WmKqU21tIW02p'

bucket_name = 'lanyu'

def storage(data):
    q=Auth(access_key,secret_key)
    token=q.upload_token(bucket_name)
    print(token)
    # up_token: 上传凭证
    # key: 上传文件名
    # data: 上传二进制流
    ret,info=put_data(token,None,data)
    print(ret)
    print(ret,info)

    if info.status_code!=200:
        raise Exception('上传图片失败')
    return ret['key']

if __name__ == '__main__':
    file=input('请输入文件路径')
    with open(file,'rb') as f:
        storage(f.read())